package com.applink.sell_proof.builder;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;

import com.applink.sell_proof.R;
import com.applink.sell_proof.model.Project;

public class SearchOpportunityBuilder extends AllProjectBuilder {

	public SearchOpportunityBuilder(Context context, ViewGroup parent) {
		super(context, parent);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.header_deal_item:
			int position = (Integer) v.getTag();
			Project project = (Project) mData.get(position);
			Intent result = new Intent();
			result.putExtra("opportunity_id", project.getId());
			result.putExtra("opportunity_name", project.getName());
			((Activity) mContext).setResult(Activity.RESULT_OK, result);
			((Activity) mContext).finish();
			break;
		case R.id.table_row_deal:
			position = (Integer) v.getTag();
			int firstItem = mListView.getFirstVisiblePosition() - mListView.getHeaderViewsCount();
			int real_position = position - firstItem;
			if (real_position >= 0 && real_position < mListView.getChildCount()) {
				View layout_item = mListView.getChildAt(real_position);
				View menu = layout_item.findViewById(R.id.deal_menu);
				menu.setVisibility(menu.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
				mSelectedPosition = menu.getVisibility() == View.VISIBLE ? position : -1;
				notifyDataChange();
			}
			break;
		default:
			break;
		}
	}
}
